<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<div style="padding: 10px">
    <form id="content">
        <table cellpadding="5">
            <tr>
                <td>
                    <input name="busId" type="hidden"/>
                </td>
            </tr>
            <tr>
                <td>车牌号:</td>
                <td><input class="easyui-textbox" type="text" name="busNumber" data-options="required:true"
                           style="width: 280px;"></input></td>
            </tr>
            <tr>
                <td>所属车队:</td>
                <td>
                    <input id="textdefaut1" name="teamName" class="easyui-combobox" data-options="
                                     method:'post',
                                     height:20,
                                     required:true" style="width: 200px"/>
                    <input id="teamId" name="teamId" type="hidden"/>
                </td>
            </tr>
            <tr>
                <td>所属线路:</td>
                <td>
                    <input id="textdefaut2" name="lineName" class="easyui-combobox" data-options="
                                     method:'post',
                                     height:20,
                                     required:true" style="width: 200px"/>
                    <input id="lineId" name="lineId" type="hidden"/>
                </td>
            </tr>
            <tr>
                <td>司机姓名:</td>
                <td><input class="easyui-textbox" type="text" name="driverName"
                           data-options="min:1,max:100,precision:0,required:true"/>
                </td>
            </tr>
            <tr>
                <td>司机电话:</td>
                <td><input class="easyui-textbox" type="text" name="driverPhone"
                           data-options="min:1,max:100,precision:0,required:true"/>
                </td>
            </tr>
            <tr>
                <td>车辆状态:</td>
                <td>
                    <input class="easyui-radio" type="radio" name="busStatus" value="1" /> 运行
                    <input class="easyui-radio" type="radio" name="busStatus" value="0" /> 停运
                </td>
            </tr>
        </table>
    </form>
    <div style="padding:5px">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
    </div>
</div>
<script type="text/javascript">

    function submitForm() {
        if (!$("#content").form('validate')) {
            $.messager.alert('提示', '请把表单填写完整');
            return;
        }
        $.post("${pageContext.request.contextPath}/bus/update", $("#content").serialize(), function (data) {
            console.log(data.code);
            if (data.code == 200) {
                $.messager.alert('提示', '修改车辆信息成功');
                $("#busUpdate").window('close');
                $("#busList").datagrid('reload');
                clearForm();
            } else {
                $.messager.alert('提示', '修改车辆信息不成功');
            }
        }, "json");
    }

    function clearForm() {
        $('#content').form('reset');
    }

    $('#textdefaut1').combobox({
        url: '${pageContext.request.contextPath}/busTeam/allBusTeam',
        valueField: 'teamId',
        textField: 'teamName',
        editable: false,
        onSelect: function (rec) {
            console.log(rec.teamName);
            $('#teamId').val(rec.teamId);
            $('#textdefaut2').combobox({
                url: '${pageContext.request.contextPath}/busLine/BusLineByTeamId?teamId=' + rec.teamId,
                valueField : 'lineId',
                textField : 'lineName',
                editable: false,
                //再写一个onselect函数，在用户更改了大队的时候，动态赋值
                onSelect: function (rec) {
                    console.log(rec.lineId);
                    $('#lineId').val(rec.lineId);
                }
            });
        }
    });


</script>
